package forward.UI;

import java.awt.Color;

import forward.UI.Font.CFontRenderer;
import forward.UI.Font.FontLoaders;
import forward.Util.ClientUtil;
import forward.Util.TimeHelper;
import forward.Util.Render.RenderUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;


public class ClientNotification {
    Minecraft mc = Minecraft.getMinecraft();
    private String message;
    private TimeHelper timer;
    private double lastY;
    private double posY;
    private double width;
    private double height;
    private double animationX;
    private int color;
    private int imageWidth;
    private ResourceLocation image;
    private long stayTime;

    public ClientNotification(final String message, final Type type) {
        this.message = message;
        (this.timer = new TimeHelper()).reset();
        final CFontRenderer font = FontLoaders.Comfortaa14;
        this.width = font.getStringWidth(message) + 20;
        this.height = 20.0;
        this.animationX = this.width;
        this.stayTime = 2000L;
        this.imageWidth = 13;
        this.posY = -1.0;
        //this.image = new ResourceLocation("UNPAssets/Notification/" + type.name().toLowerCase() + ".png");
        this.color = new Color(30, 30, 30, 220).getRGB();
    }

    public void draw(final double getY, final double lastY) {
        this.lastY = lastY;
        double Speed = Math.abs(this.animationX - (this.isFinished() ? this.width : 0.0)) * 20.0;
        if (ClientUtil.notifications.size() > 15) {
            Speed = Math.abs(this.animationX - (this.isFinished() ? this.width : 0.0)) * 5.0 * 20;
        }
        this.animationX = RenderUtil.getAnimationState(this.animationX, this.isFinished() ? this.width : 0.0, Math.max(this.isFinished() ? 200 : 30, Speed));
        if (this.posY == -1.0) {
            this.posY = getY;
        } else {
            this.posY = RenderUtil.getAnimationState(this.posY, getY, 300);
        }
        final ScaledResolution res = new ScaledResolution(Minecraft.getMinecraft());
        final int x1 = (int) (res.getScaledWidth() - this.width + this.animationX);
        final int x2 = (int) (res.getScaledWidth() + this.animationX);
        final int y1 = (int) this.posY;
        final int y2 = (int) (y1 + this.height);
        Gui.drawRect(x1, y1, x2, y2, this.color);
        // Gui.drawRect(x1, y2, x2, y2 + 0.5f, this.color);
        // Gui.drawRect(x1, y2, x2, y2 + 0.5f, ClientUtil.reAlpha(1, 0.5f));
        //Gui.drawRect(x1, y1, (int)(x1 + this.height), y2, ClientUtil.reAlpha(-1, 0.1f));
        //  RenderUtil.drawImage(this.image, (int)(x1 + (this.height - this.imageWidth) / 2.0), y1 + (int)((this.height - this.imageWidth) / 2.0), this.imageWidth, this.imageWidth);
        final CFontRenderer font = FontLoaders.Comfortaa16;
        font.drawCenteredString(this.message, (float) this.animationX + RenderUtil.width() - font.getStringWidth(message) / 2 - 5, (float) (y1 + this.height / 3.5) + 3.0f, -1);
    }

    public boolean shouldDelete() {
        return this.isFinished() && this.animationX >= this.width;
    }

    private boolean isFinished() {
        return this.timer.isDelayComplete(this.stayTime) && this.posY == this.lastY;
    }

    public double getHeight() {
        return this.height;
    }

    public enum Type {
        SUCCESS("SUCCESS", 0),
        INFO("INFO", 1),
        WARNING("WARNING", 2),
        ERROR("ERROR", 3);

        private Type(final String s, final int n) {
        }
    }
}

